package homework.hoomework_10.phone;

import java.util.ArrayList;

/**
 * @author 朱
 * @date 2019042221:48
 */
public class PhoneDaoSet implements PhoneDao {
    ArrayList<Phone> arrayList=new ArrayList<Phone>();
    @Override
    public void stock(Phone phone) {
    arrayList.add(phone);
    }

    @Override
    public void select_type(String type) {
        for (int i = 0; i <arrayList.size() ; i++) {
            if (arrayList.get(i).getType().equals(type)){
                System.out.println(arrayList.get(i));
            }else {
                System.out.println("手机型号不存在！");
            }
        }
    }

    @Override
    public void select_name(String name) {
        for (int i = 0; i <arrayList.size() ; i++) {
            if (arrayList.get(i).getName().equals(name)){
                System.out.println(arrayList.get(i));
            }else{
                System.out.println("手机型号不存在！");
            }
        }
    }

    @Override
    public void selectAll() {
        System.out.println(arrayList);
    }

    @Override
    public void delete(String type, String name) {
        for (int i = 0; i <arrayList.size() ; i++) {
            if (arrayList.get(i).getType().equals(type)&&arrayList.get(i).getName().equals(name)){
                arrayList.remove(arrayList.get(i));
            }else {
                System.out.println("您要删除的手机不存在");
            }
        }
    }
}
